#pragma once
#include<iostream>
#include<signal.h>
#include<cstdlib>
#include<sys/types.h>
#include<unistd.h>
#include<cassert>
#include<sys/stat.h>
#include <fcntl.h>

#define DEV "dev/null/"


void deamonSelf(const char*currPath=nullptr )
{
  signal(SIGPIPE,SIG_IGN); 
   
  if(fork()>0)
  {
    exit(1);
  }
  pid_t n=setsid();
    assert(n != -1);
 int fd=open(DEV,O_RDWR);
 if(fd>=0)
 {
    dup2(fd,0);
    dup2(fd,1);
    dup2(fd,2);
    close(fd);

 }
 else{
    close(0);
    close(1);
    close(2);
 }
    if(currPath) chdir(currPath);
  

}